#include "openfiledialog.h"
#include <QGridLayout>
#include <QLabel>
#include <QTextEdit>


const QString OpenFileDialog::filterDPO = "DPO files (*.dpo *)";
const QString OpenFileDialog::filterSIG = "SIG (*.bin *.sig *)";
const QString OpenFileDialog::filterALL = "Any files (*)";


OpenFileDialog::OpenFileDialog(QWidget *parent)
	: QFileDialog(parent, tr("Open File"), QDir::homePath())
	, _label(new QLabel(tr("Split at(in bytes)"), this))
	, _spinbox(new QSpinBox(this))
	, _isSIG(false)
{
	_spinbox->setMinimum(1);
	_spinbox->setMaximum(INT_MAX);

	_label->setVisible(false);
	_spinbox->setVisible(false);

	QLayout* layout = this->layout();
	QGridLayout* gridbox = qobject_cast<QGridLayout*>(layout);

	gridbox->addWidget(_label);
	gridbox->addWidget(_spinbox);

	setDirectory(QDir::currentPath());
	setFileMode(ExistingFile);

	_filters << filterDPO
		<< filterSIG
		<< filterALL;

	setNameFilters(_filters);

	connect(this, SIGNAL(filterSelected (QString)), this, SLOT(on_filterSelected(QString)));
}

OpenFileDialog::~OpenFileDialog()
{

}

void OpenFileDialog::on_filterSelected( const QString & filter )
{
	if (filter == filterSIG)
	{
		_label->setVisible(true);
		_spinbox->setVisible(true);
		_isSIG = true;
	}
	else
	{
		_label->setVisible(false);
		_spinbox->setVisible(false);
		_isSIG = false;
	}
}

int OpenFileDialog::getSplitSize() const
{
	return _isSIG ? _spinbox->value() : -1;
}
